﻿using System;

namespace YArchitech.MEP
{
	public static class HYMathUtility
	{
		public static bool IsZero(double d, double prec = 0.001)
		{
			return Math.Abs(d) < prec;
		}

		public static bool IsEqual(double a, double b, double prec = 0.001)
		{
			return HYMathUtility.IsZero(a - b, prec);
		}

		public static double Volume(double mass, double density)
		{
			if (HYMathUtility.IsZero(density, 0.001))
			{
				return 0.0;
			}
			return mass / density;
		}

		public static double Mass(double volume, double density)
		{
			return volume * density;
		}

		public static double Area_Rectangular(double w, double h)
		{
			return w * h;
		}

		public static double Circumference_Rectangular(double w, double h)
		{
			return 2.0 * (w + h);
		}

		public static double Area_Round(double diameter)
		{
			return Math.PI * diameter * diameter / 4.0;
		}

		public static double Circumference_Round(double diameter)
		{
			return Math.PI * diameter;
		}

		public static double Diameter(double area)
		{
			return 2.0 * Math.Sqrt(area / Math.PI);
		}

		public static double Circumference_Oval(double longAxis, double shortAxis)
		{
			double num = Math.Max(longAxis, shortAxis);
			double num2 = Math.Min(longAxis, shortAxis);
			return Math.PI * num2 + 2.0 * (num - num2);
		}

		public static double Area_Oval(double longAxis, double shortAxis)
		{
			double num = Math.Max(longAxis, shortAxis);
			double num2 = Math.Min(longAxis, shortAxis);
			return HYMathUtility.Area_Round(num2) + HYMathUtility.Area_Rectangular(num - num2, num2);
		}

		public static double RToD(double r)
		{
			return 180.0 * r / Math.PI;
		}

		public static double DToR(double d)
		{
			return d * Math.PI / 180.0;
		}

		public const double PRECISION1 = 0.1;

		public const double PRECISION2 = 0.01;

		public const double PRECISION3 = 0.001;

		public const double PRECISION4 = 0.0001;

		public const double PRECISION5 = 1E-05;

		public const double PRECISION6 = 1E-06;

		public const double PRECISION7 = 1E-07;

		public const double PRECISION8 = 1E-08;

		public const double PRECISION9 = 1E-09;
	}
}
